namespace GemBox.Spreadsheet
{
    using System;
    using System.Drawing;

    public sealed class ExcelFillPattern
    {
        private CellStyle parent;

        internal ExcelFillPattern(CellStyle parent)
        {
            this.parent = parent;
        }

        internal void CopyTo(CellStyle destination)
        {
            destination.Element.PatternStyle = this.parent.Element.PatternStyle;
            destination.Element.PatternForegroundColor = this.parent.Element.PatternForegroundColor;
            destination.Element.PatternBackgroundColor = this.parent.Element.PatternBackgroundColor;
            destination.UseFlags &= ~CellStyleData.Properties.PatternRelated;
            destination.UseFlags |= this.parent.UseFlags & CellStyleData.Properties.PatternRelated;
        }

        public void SetPattern(FillPatternStyle patternStyle, Color foregroundColor, Color backgroundColor)
        {
            this.PatternStyle = patternStyle;
            this.PatternForegroundColor = foregroundColor;
            this.PatternBackgroundColor = backgroundColor;
        }

        public void SetSolid(Color fillColor)
        {
            this.PatternStyle = FillPatternStyle.Solid;
            this.PatternForegroundColor = fillColor;
        }

        public Color PatternBackgroundColor
        {
            get
            {
                return this.parent.Element.PatternBackgroundColor;
            }
            set
            {
                this.parent.BeforeChange();
                this.parent.Element.PatternBackgroundColor = value;
                this.parent.UseFlags |= CellStyleData.Properties.PatternBackgroundColor;
            }
        }

        public Color PatternForegroundColor
        {
            get
            {
                return this.parent.Element.PatternForegroundColor;
            }
            set
            {
                this.parent.BeforeChange();
                this.parent.Element.PatternForegroundColor = value;
                this.parent.UseFlags |= CellStyleData.Properties.PatternForegroundColor;
            }
        }

        public FillPatternStyle PatternStyle
        {
            get
            {
                return this.parent.Element.PatternStyle;
            }
            set
            {
                this.parent.BeforeChange();
                this.parent.Element.PatternStyle = value;
                this.parent.UseFlags |= CellStyleData.Properties.PatternStyle;
            }
        }
    }
}
